import 'package:flutter/material.dart';
import 'package:hi_flutter/app_page.dart';

class PageViewDemoPage extends StatelessWidget {
  const PageViewDemoPage({super.key});

  @override
  Widget build(BuildContext context) {
    var children = <Widget>[];
    // 生成 6 个 Tab 页
    for (int i = 0; i < 6; ++i) {
      children.add(Page(text: '$i'));
    }

    //             // independent of implicit scrolling:
    //             // https://github.com/flutter/flutter/issues/45632
    //             cacheExtent: widget.allowImplicitScrolling ? 1.0 : 0.0,
    //             cacheExtentStyle: CacheExtentStyle.viewport,
    return AppPage(
      body: PageView(
        // allowImplicitScrolling: true,
        children: children,
      ),
    );
  }
}

class Page extends StatefulWidget {
  final String text;

  const Page({super.key, required this.text});

  @override
  State<Page> createState() => _PageState();
}

class _PageState extends State<Page> with AutomaticKeepAliveClientMixin{
  @override
  Widget build(BuildContext context) {
    print("build ==> ${widget.text}");
    super.build(context);
    return Center(
      child: Text(
        widget.text,
        textScaler: const TextScaler.linear(5),
      ),
    );
  }

  @override
  bool get wantKeepAlive => true;
}
